package racer.client.gui;

/**
 *
 * @author Lieven
 * 
 */
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.ComponentOrientation;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import racer.client.data.print;
import racer.client.gui.tiles.Tile;
import racer.client.gui.tiles.TileTypeNeighbours;
import racer.client.gui.MapGenerator.DrawingCanvas.InputHandler;
import racer.client.gui.tiles.TiledMap;

public class MapGenerator extends JFrame implements ActionListener{
DrawingCanvas canvas;
BufferedImage V,H,K1,K2,K3,K4,HFIN,VFIN,OPEN,SAVE,EXPORTMAP,CLEARMAP;
Image afbeelding;
JLabel label;
JButton button;
public ArrayList approvedTileTypeMap;
boolean isMapCircular=false;

boolean chosenNewTileType=false;
boolean allElementsUsedInChainedMap = true;
boolean enter_pushed=false;
boolean finish_line_present=false;
public int startmapMINY;
public int startmapMINX;
int rows=6;
int cols=10;
//init this or with boolean
//boolean chosenTileType=false;
public String tile_type="K2";
BufferStrategy strategy;
        
public Image buf;
public Graphics gbuf;
public Image achtergrond;
public ArrayList entereditems;
public int entered_teller=0;
private boolean tile_approved=true;
public HashMap tile_map,tilebufim,chosenmap,typetilemap;
public HashMap tileIDdistanceBetweenDirectionsMap,tiletypeneighboursmap;
boolean gameRunning=true;
public int active_tile=1;
public ImageBank ib;
public JPanel panel_map,panel_buttons,panel_statusbar;
public JToolBar toolBar;
public Image backgroundImage,image_buffer;
public Graphics bufferScreen;


  public MapGenerator()  {
    super();
    ib = new ImageBank();
    //this order!
    loadImages();
    initHashMaps();
    print.tiles(tile_map);
    
    //toolbar panel and components
    panel_buttons = new JPanel();
    panel_buttons.setLayout(new GridLayout(1, 1));        
    toolBar = new JToolBar("Open/Save/Export/Choose tile");
    addButtons(toolBar);
    toolBar.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);    
    panel_buttons.add(toolBar);
    panel_buttons.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);    

    //statusbar panel and components
    panel_statusbar = new JPanel();
    panel_statusbar.setLayout(new GridLayout(6, 1));
    panel_statusbar.setSize(1000, 30);    
    label=new JLabel("Welcome");
    label.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    panel_statusbar.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);    
    panel_statusbar.add(label,BorderLayout.NORTH);
    
    //canvas/map panel and components
    panel_map = new JPanel();
    panel_map.setLayout(new GridLayout(1, 1));
    //not using panel_map?
    canvas = new DrawingCanvas();
    
    //container that contains all panels
    Container container = getContentPane();
    container.add(panel_map, BorderLayout.CENTER);
    container.add(panel_buttons, BorderLayout.NORTH);
    container.add(panel_statusbar,BorderLayout.SOUTH);
    container.add(canvas);

    addWindowListener(new WindowEventHandler());
    setTitle("MapGen 1.0");
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    setSize(dim);
    setVisible(true);
    
    setBackground(Color.white);  
    image_buffer = createImage(1024,900);
    backgroundImage = createImage(1024,900);
    TiledMap.drawRasteredMap(backgroundImage.getGraphics(),cols,rows,100,100);
    canvas.requestFocus();
    
    
         
    
  }

  public void loadImages(){
         
           K1 = ib.getImage("b1");
           K2 = ib.getImage("b2");
           K3 = ib.getImage("b3");
           K4 = ib.getImage("b4");
           V = ib.getImage("vert");
           H = ib.getImage("hori");
           VFIN = ib.getImage("vertifin");
           HFIN = ib.getImage("horifin");
            SAVE = ib.getImage("save");
            OPEN = ib.getImage("open");
            CLEARMAP = ib.getImage("clearmap");
            EXPORTMAP = ib.getImage("exportmap");                    
      
  }
  
  public void initHashMaps(){

   //centrale hashmapbank?

   //voor controle tiles bij het plaatsen

   //met bits geïnitialiseerde objecten (per type tile 1 bits ingesteld
   //voor de richting die de auto kan uitgaan (afh van type tile) -> type,links,rechts,top,bottom)
   //o.a. cruciaal bij het linken van de eerste tile met de laatste op het einde

   TileTypeNeighbours ttnH = new TileTypeNeighbours("H",1,1,0,0);
   TileTypeNeighbours ttnV = new TileTypeNeighbours("V",0,0,1,1);
   TileTypeNeighbours ttnK1 = new TileTypeNeighbours("K",1,0,0,1);
   TileTypeNeighbours ttnK2 = new TileTypeNeighbours("K2",0,1,0,1);
   TileTypeNeighbours ttnK3 = new TileTypeNeighbours("K3",0,1,1,0);
   TileTypeNeighbours ttnK4 = new TileTypeNeighbours("K4",1,0,1,0);

   tiletypeneighboursmap= new HashMap();
   tiletypeneighboursmap.put("H", ttnH);
   tiletypeneighboursmap.put("HFIN", ttnH);
   tiletypeneighboursmap.put("V", ttnV);
   tiletypeneighboursmap.put("VFIN", ttnV);
   tiletypeneighboursmap.put("K1", ttnK1);
   tiletypeneighboursmap.put("K2", ttnK2);
   tiletypeneighboursmap.put("K3", ttnK3);
   tiletypeneighboursmap.put("K4", ttnK4);  

   //nodig voor analyse (afstanden tussen tiles...tile boven = tileid-10
   tileIDdistanceBetweenDirectionsMap=new HashMap();
   tileIDdistanceBetweenDirectionsMap.put("links",-1);
   tileIDdistanceBetweenDirectionsMap.put("rechts",1);
   tileIDdistanceBetweenDirectionsMap.put("boven",-10);
   tileIDdistanceBetweenDirectionsMap.put("onder",10);


   //per type pic een cijfer (switch case -> int)
   typetilemap=new HashMap();
   typetilemap.put("H","1");
   typetilemap.put("HFIN","1");
   typetilemap.put("V","2");
   typetilemap.put("VFIN","2");
   typetilemap.put("K1","3");
   typetilemap.put("K2","4");
   typetilemap.put("K3","5");
   typetilemap.put("K4","6");                
           
   tilebufim=new HashMap();
   tilebufim.put("V", V);
   tilebufim.put("VFIN", VFIN);
   tilebufim.put("H", H);
   tilebufim.put("HFIN", HFIN);
   tilebufim.put("K1", K1);
   tilebufim.put("K2", K2);
   tilebufim.put("K3", K3);
   tilebufim.put("K4", K4);        
   
   
   TiledMap.buildRasteredMap(this,cols,rows,100,100);
   
    
  }
  
  /*
   * GUI methods
   * 
   * */
  
  protected void addButtons(JToolBar toolBar) {
      
        

        toolBar.add(makeNavigationButton("CLEARMAP","Clear this map",CLEARMAP));        
        toolBar.add(makeNavigationButton("OPEN","Open a map project",OPEN));
        toolBar.add(makeNavigationButton("SAVE","Save a map project",SAVE));
        toolBar.add(makeNavigationButton("EXPORTMAP","Export a saved map project as a functional map",EXPORTMAP));
        
        toolBar.add(makeNavigationButton("K1","Kwadrant 1 (K1)",K1));
        toolBar.add(makeNavigationButton("K2","Kwadrant 2 (K2)",K2));
        toolBar.add(makeNavigationButton("K3","Kwadrant 3 (K3)",K3));
        toolBar.add(makeNavigationButton("K4","Kwadrant 4 (K4)",K4));
        toolBar.add(makeNavigationButton("H","Horizontal (H)",H));
        toolBar.add(makeNavigationButton("HFIN","Horizontal with finish line (HFIN)",HFIN));
        toolBar.add(makeNavigationButton("V","Vertical (V)",V));
        toolBar.add(makeNavigationButton("VFIN","Vertical with finish line (VFIN)",VFIN));          
      
        
        

        
    }

  protected JButton makeNavigationButton(String actionCommand,String toolTipText,BufferedImage bf) {
       
        button = new JButton();
        ImageIcon icon = new ImageIcon();
        icon.setImage(ImageBank.getScaledImage(bf,50,50));      
        button.setIcon(icon);
        button.setActionCommand(actionCommand);
        button.setToolTipText(toolTipText);
        button.addActionListener(this);        

        return button;
    }

  
    


  public static void main(String arg[]) {
    new MapGenerator();
  }
  


  
  
/*
  * Methods used by TiledMap (getters/setters) loading/saving/exporting (project) map
  * 
  * */

    public void setChosenMap(HashMap chosenmap){
        this.chosenmap=chosenmap;
    }
    public HashMap getChosenMap(){
        return chosenmap;
    }      

    public void setTileMap(HashMap tile_map){
        this.tile_map=tile_map;
    }    
    public HashMap getTileMap(){
        return tile_map;
    }          
    public HashMap getTypetilemap(){
        return typetilemap;
    }
    
    public HashMap gettileIDdistanceBetweenDirectionsMap(){
        return tileIDdistanceBetweenDirectionsMap;
    }
    //later via hashmap van booleans en 1 methode?
    
    public void setfinish_line_present(boolean finish_line_present){
        this.finish_line_present=finish_line_present;
    }    

    public void setisMapCircular(boolean isMapCircular){
        this.isMapCircular=isMapCircular;
    }        

    public void setallElementsUsedInChainedMap(boolean allElementsUsedInChainedMap){
        this.allElementsUsedInChainedMap=allElementsUsedInChainedMap;
    }        

    public int getActiveTile(){
        return active_tile;
    }        
    public HashMap getTiletypeneighboursmap(){
        return tiletypeneighboursmap;
    }
    
    public boolean isFinishLinePresent(){
        return finish_line_present;
    }

    
 /*
  * Methods (interactive ~ pushing buttons in toolbars)
  * 
  * */           


  
 public void actionPerformed(ActionEvent evt) 
         {
     
                     
     
                
     if(evt.getActionCommand().equals("SAVE")){
         System.out.println("SAVE");
         
         if(TiledMap.saveMapInProgress(this,"3.txt")){
             label.setText("<html><font color='green'>CONFIRMATION: The Project has been successfully saved!</font></html>");         
             System.out.println("FILE SUCCESFULLY SAVED");
         }else{
             System.out.println("SAVE FAILED");
             label.setText("<html><font color='red'>ERROR: saving failed!</font></html>");             
         }
             
     }else if(evt.getActionCommand().equals("OPEN")){
         
         
         if(TiledMap.loadMapInProgress(this,"3.txt")){
             label.setText("<html><font color='green'>CONFIRMATION: The Project has been successfully opened! </font></html>");                      
             canvas.repaint();
             System.out.println("FILE SUCCESFULLY LOADED");
         }else{
             System.out.println("LOADING FAILED");
             label.setText("<html><font color='red'>ERROR: loading failed (perhaps empty or 'map.txt' file)!</font></html>");             
         }
         
     }else if(evt.getActionCommand().equals("EXPORTMAP")){
         if(finish_line_present){
             if(TiledMap.exportMap(this)){
             label.setText("<html><font color='green'>CONFIRMATION: The Project has been successfully exported!</font></html>");             
             }else{
                     if(!allElementsUsedInChainedMap)
                     {
                         label.setText("<html><font color='red'>ERROR: you have a circular chain ... yes but not all elements are used in the chain !(please add the loose elements in the chain or remove them)</font></html>");   
                         
                     }else if(!isMapCircular){        
                        label.setText("<html><font color='red'>ERROR: before u can export this project as a map, you need to have a CIRCULAR MAP (last and first tile needs to be linked,all tiles chained to each other)!</font></html>");
                         
                     }else{
                         label.setText("<html><font color='red'>ERROR: saving failed!</font></html>");                                                                     
                     }
               
             }
             
         }else{
             label.setText("<html><font color='red'>ERROR: before u can export this project as a map, you need to have a FINISH LINE TILE (HFIN or VFIN)!</font></html>");
         }         
     }else if(evt.getActionCommand().equals("CLEARMAP")){
         
        chosenmap = new HashMap();
        finish_line_present=false;
        isMapCircular = false;
        allElementsUsedInChainedMap = true;
        label.setText("<html><font color='green'>CONFIRMATION: The Map has been successfully SWEEPED/WIPED!</font></html>");             
        canvas.repaint();
     
     }else{
         
       
            tile_type = evt.getActionCommand();
            //chosenTileType=true;
            chosenNewTileType=true;
            System.out.println(tile_type);
            
            canvas.repaint();


     }
     canvas.requestFocus();
 }


  /*
  * Methods to paint tiles
  * 
  * */   
  class WindowEventHandler extends WindowAdapter {
    public void windowClosing(WindowEvent e) {
      System.exit(0);
    }
  }
  class DrawingCanvas extends Canvas {
    //MapGenerator mapg;
    public DrawingCanvas() {

      addKeyListener(new InputHandler());
      createBufferStrategy(1);
      strategy = getBufferStrategy();
      setSize(1024, 900);
      //this.mapg=mapg;


    }

    public void update(Graphics g) {
      paint(g);
    }


   public void paintFillChosenTiles(Graphics bufferScreen){
   
        Iterator cmIterator = chosenmap.keySet().iterator();
        while(cmIterator.hasNext()) {
            int mid = (Integer)cmIterator.next();
            String type = (String)chosenmap.get(mid);
            System.out.println("saved tile ID:"+mid);
            if(active_tile == mid){
                TiledMap.paintFillActiveTile(bufferScreen,((Tile)tile_map.get(mid)).x,((Tile)tile_map.get(mid)).y,((Tile)tile_map.get(mid)).width,((Tile)tile_map.get(mid)).height,(BufferedImage)tilebufim.get(tile_type));                                
            }else{
                TiledMap.paintFillActiveTile(bufferScreen,((Tile)tile_map.get(mid)).x,((Tile)tile_map.get(mid)).y,((Tile)tile_map.get(mid)).width,((Tile)tile_map.get(mid)).height,(BufferedImage)tilebufim.get(type));                    
            }
            
        }       
       
       
   }
   

    public void paint(Graphics g) {

        bufferScreen = image_buffer.getGraphics();  
        bufferScreen.drawImage(backgroundImage, 0, 0, null);
        
        //paint each filled tile of chosenmap
        paintFillChosenTiles(bufferScreen);

        //current tiletype in active tile (overwrite normal map)
        TiledMap.paintFillActiveTile(bufferScreen,((Tile)tile_map.get(active_tile)).x,((Tile)tile_map.get(active_tile)).y,((Tile)tile_map.get(active_tile)).width,((Tile)tile_map.get(active_tile)).height,(BufferedImage)tilebufim.get(tile_type));
        if(tile_approved ){        
            TiledMap.paintActiveTileBounds(bufferScreen,((Tile)tile_map.get(active_tile)).x,((Tile)tile_map.get(active_tile)).y,((Tile)tile_map.get(active_tile)).width,((Tile)tile_map.get(active_tile)).height);
        }else if (chosenNewTileType){
            TiledMap.paintActiveTileBounds(bufferScreen,((Tile)tile_map.get(active_tile)).x,((Tile)tile_map.get(active_tile)).y,((Tile)tile_map.get(active_tile)).width,((Tile)tile_map.get(active_tile)).height);
        }else{

            TiledMap.paintTileError(bufferScreen,((Tile)tile_map.get(active_tile)).x,((Tile)tile_map.get(active_tile)).y,((Tile)tile_map.get(active_tile)).width,((Tile)tile_map.get(active_tile)).height);
        }

        bufferScreen.dispose();
        g.drawImage(image_buffer,0,0,this); 
            
            
           

           
    }

 
 /*
  * Methods (interactive ~ pushing KEYBOARD f.e. ENTER)
  * 
  * */           
    
    class InputHandler extends KeyAdapter {
        public ArrayList approvedTileTypeMap;
        public boolean tileGotApproved(){
            return makeApprovedTypesMap();
            
        }

        public boolean isChosenTileTypeValid(String tilesoort,int bottom_newtile_state,int top_newtile_state,int left_newtile_state,int right_newtile_state){
            TileTypeNeighbours ttn2compare = ((TileTypeNeighbours) tiletypeneighboursmap.get(tilesoort));
            if((bottom_newtile_state != -1)&&((ttn2compare.getBottom()) != bottom_newtile_state)){
                return false;
            }else if((top_newtile_state != -1)&&((ttn2compare.getTop()) != top_newtile_state)){
                return false;
            }else if((right_newtile_state != -1)&&((ttn2compare.getRight()) != right_newtile_state)){
                return false;
            }else if((left_newtile_state != -1)&&((ttn2compare.getLeft()) != left_newtile_state)){
                return false;
            }else{
                return true;
            }

        }
        
        public boolean makeApprovedTypesMap(){
            approvedTileTypeMap = new ArrayList();

            int leftid=active_tile-1;
            //-1  -> carte blanche,later wordt het overschreven als het in de
            //chosenmap zit(map met ids van tiles die bezet/gevuld zijn)
            //als het er niet inzit-> carte blanche = -1 (dus geen else meer schrijven)
            int left_newtile_state=-1;

            int rightid=active_tile+1;
            int right_newtile_state=-1;

            int topid=active_tile-10;
            int top_newtile_state=-1;

            int bottomid=active_tile+10;
            int bottom_newtile_state=-1;

            if (chosenmap.containsKey(leftid)){
                //adhv type van linkerbuurtile->zien welke rand ok is en welke niet
                //als rechtrmuur=1 is de weg vrij bv horizontale tile => linkerrand van de nieuwe tile
                //dat men wil instellen moet ook vrij zijn
                left_newtile_state=((TileTypeNeighbours) tiletypeneighboursmap.get((String)chosenmap.get(leftid))).getRight();
            }

            if (chosenmap.containsKey(rightid)){
                right_newtile_state=((TileTypeNeighbours) tiletypeneighboursmap.get((String)chosenmap.get(rightid))).getLeft();
            }
            if (chosenmap.containsKey(topid)){
                top_newtile_state=((TileTypeNeighbours) tiletypeneighboursmap.get((String)chosenmap.get(topid))).getBottom();
            }
            if (chosenmap.containsKey(bottomid)){
                bottom_newtile_state=((TileTypeNeighbours) tiletypeneighboursmap.get((String)chosenmap.get(bottomid))).getTop();
            }

            //extra controle op de 4 al dan niet toegestande richtingen -> voor de randen van het traject
            Tile t = (Tile) tile_map.get(active_tile);
            //uiterste coordinaten
            //later berekenen uit de dimensie -> x_max = (aantalvakjesX-1)*100 ,y_max = (aantalvakjesY-1)*100
            //10 vakjes horizontaal => laatste begint op coordinaat (900,y)
            //elk vak is 100 breed en eerste vak begint op (0,0)
            int xbound=((cols-1)*100);
            int ybound=((rows-1)*100);
            if(t.x == 0)
                left_newtile_state = 0;
            if(t.x == xbound)
                right_newtile_state = 0;
            if(t.y == 0)
                top_newtile_state = 0;
            if(t.y == ybound)
                bottom_newtile_state = 0;

            //nu zijn de 4 richtingen gekend en kan men ze vergelijken met alle types tiles
            //vooral om lijst van mogelijke tiletypes te tonen als de gekozen tile soort fout is


            Iterator cmIterator = typetilemap.keySet().iterator();
            while(cmIterator.hasNext()) {
                String tilesoort = (String)cmIterator.next();


                if(isChosenTileTypeValid(tilesoort,bottom_newtile_state,top_newtile_state,left_newtile_state,right_newtile_state)){
                    approvedTileTypeMap.add(tilesoort);
                }
                //System.out.println("saving mapInProgress tile ID:"+mid+", type"+type+"=");

            }

            if((finish_line_present)&&(tile_type.equals("HFIN"))||((tile_type.equals("VFIN")))){
                //beide finish lines verwijderen (there can be only one)
                //approvedTileTypeMap.remove(tile_type);
                if (approvedTileTypeMap.contains("HFIN"))
                    approvedTileTypeMap.remove("HFIN");
                if (approvedTileTypeMap.contains("VFIN"))
                    approvedTileTypeMap.remove("VFIN");
            }


            //afh van check
            if((approvedTileTypeMap.isEmpty()) || (approvedTileTypeMap.indexOf(tile_type) == -1)){
            return false;
            }else{
            return true;
            }

        }
        
        @Override
        public void keyPressed(KeyEvent e) {
            synchronized (this) {
                
                
                    
                
            
            
            
                
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                    enter_pushed=true;
              //  if(chosenTileType){
                    if (chosenmap.containsKey(active_tile)){
                        //tile_type=gekozen tile..enkel van tel bij adden van elementen
                        //bij deleten moet je tile type van de actieve tile opvragen
                        
                        if((chosenmap.get(active_tile).equals("HFIN"))||((chosenmap.get(active_tile).equals("VFIN")))){
                            finish_line_present=false;                        
                        
                        }
                        chosenmap.remove(active_tile);                            
                    

                    }else{

                        if(tileGotApproved()){
                            label.setText("type "+tile_type+ " approved and set!");
                            tile_approved=true;
                            if((tile_type.equals("HFIN"))||((tile_type.equals("VFIN"))))
                                finish_line_present=true;
                            chosenmap.put(active_tile,tile_type);   
                            
                            
                        }else{
                            tile_approved=false;
                            //also false so that he will keep painting error picture as tile
                            //only when chosen new tile type..it dissapears
                            chosenNewTileType=false;
                            String labeltext = "<html><font color='black'>type "+tile_type+ " not approved. Possible tile types:<font color='red'>";                            
                            //String labeltext="type "+tile_type+ " not approved. Please choose a good one!\n";
                            
                            if(approvedTileTypeMap.size() >0){
                                Iterator<String> itr = approvedTileTypeMap.iterator();
                                while (itr.hasNext()) {
                                 String element = itr.next();
                                  labeltext+=" "+element;
                                }
                            }else{
                                labeltext+="None! Please choose another tile to fill or reorganise the map! ";
                            }

                            
                            if((finish_line_present)&&(tile_type.equals("HFIN"))||((tile_type.equals("VFIN"))))
                                    labeltext+=" You can have ONLY ONE FINISH LINE !!";
                            labeltext+="</font></html>";
                            label.setText(labeltext);

                            System.out.println("type "+tile_type+ " not approved. Please choose a good one!");
                        }
                      

                    //entereditems.add(entered_teller,active_tile);    
                    }
               // }else{
                 //       tile_approved=false;
                //        label.setText("<html><font color='red'>ERROR: Please choose a tile type before you try to fill a tile!</font></html>");
                //}
            }else{
                    enter_pushed=false;
            }
            
            
            
            if (e.getKeyCode() == KeyEvent.VK_LEFT) {
                System.out.println("going left");
                if(active_tile-1>0)
                    active_tile--;
                    tile_approved=true;
            }
            if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
                if(active_tile+1<=tile_map.size())
                    active_tile++;
                    tile_approved=true;
            }
            if (e.getKeyCode() == KeyEvent.VK_UP) {
                if(active_tile-10>0)
                   active_tile-=10;
                   tile_approved=true;
           
            }
            if (e.getKeyCode() == KeyEvent.VK_DOWN) {
                if(active_tile+10<=tile_map.size())
                    active_tile+=10;
                    tile_approved=true;
            }
          }
            repaint();
        }

        @Override
        public void keyReleased(KeyEvent e) {
            synchronized (this) {
            if (e.getKeyCode() == KeyEvent.VK_LEFT) {

               

            }
            if (e.getKeyCode() == KeyEvent.VK_RIGHT) {

        
               

            }
            if (e.getKeyCode() == KeyEvent.VK_UP) {

 
            }
            if (e.getKeyCode() == KeyEvent.VK_DOWN) {

                }                     
                
            }}
        }

        
    }    
    
    
  }
    